home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 103 / MacAddict_103_2005-03.iso / Software / Graphics & Multimedia / MulleSight 1.0.9.dmg / MulleSightPlusTunes.applescript < prev    next >
Encoding:
Text File  |  2004-12-03  |  6.4 KB  |  207 lines

  1. property playerstate : "off"
  2.  
  3. tell application "Finder"
  4.     set x to name of every process
  5. end tell
  6.  
  7. if ("iChat" is not in x) then
  8.     return null
  9. end if
  10.  
  11. if ("MulleSight" is in x) then
  12.     
  13.     tell application "iChat"
  14.       set image to image of application "MulleSight"
  15.     end tell
  16. end if
  17.  
  18. if ("iTunes" is not in x) then
  19.     return null
  20. end if
  21.  
  22. tell application "iTunes"
  23.     if player state is stopped then
  24.         if playerstate is not "stopped" then
  25.             set playerstate to "stopped"
  26.             return "Quiet"
  27.         end if
  28.         return null
  29.     end if
  30.     
  31.     set trackkind to kind of current track
  32.     set trackname to name of current track
  33.     set trackpos to "00:00"
  34.     if player position > 0 then
  35.         set trackpos to ""
  36.         set p to player position
  37.         set hr to p div 3600
  38.         set min to (p div 60) - (hr * 60)
  39.         set sec to (((p / 60) - (p div 60)) * 60) div 1
  40.         if (min < 10) then set min to "0" & min
  41.         if (sec < 10) then set sec to "0" & sec
  42.         if character 2 of (sec as string) = "8" then set sec to sec & " "
  43.         if hr > 0 then set trackpos to hr & ":"
  44.         set trackpos to trackpos & min & ":" & sec
  45.     end if
  46.     
  47.     set prefix to ""
  48.     set title to null
  49.     if player state is paused then set prefix to "Paused: "
  50.     if mute then set prefix to "Muted: "
  51.     if sound volume = 0 then set prefix to "Silent: "
  52.     if size of current track is missing value and time of current track is missing value then
  53.         set trackaddr to address of current track
  54.         set trackgenre to genre of current track
  55.         set myurl to null
  56.         if trackname contains "somewhere.com" then set myurl to "http://www.somewhere.com:8000/list.cgi"
  57.         if trackname contains "grassyhill.org" then set myurl to "http://radio.grassyhill.org"
  58.         if myurl is not null then
  59.             set tmpfile to ((path to temporary items) as string) & "cursong.txt"
  60.             --if exists file tmpfile then
  61.             --tell application "Finder" to delete file tmpfile
  62.             --end if
  63.             tell application "URL Access Scripting"
  64.                 download myurl to file tmpfile replacing yes
  65.             end tell
  66.             set tfile to open for access file tmpfile
  67.             
  68.             set fcontents to read tfile using delimiter {"<", ">"}
  69.             close access tfile
  70.             --tell application "Finder" to delete file tmpfile
  71.         end if
  72.         if trackname contains "somewhere.com" then
  73.             set taglist to {"Title", "tr", "localhost"}
  74.             repeat with i from 1 to number of items in fcontents
  75.                 if item i of fcontents is item 1 of taglist then
  76.                     if number of items in taglist = 1 then
  77.                         set title to ((item (i + 12) of fcontents) as string) & " - " & "ns2.somewhere.com:8000/remote"
  78.                         exit repeat
  79.                     else
  80.                         set taglist to (items 2 thru (number of items in taglist)) of taglist
  81.                     end if
  82.                 end if
  83.             end repeat
  84.         else if trackname contains "grassyhill.org" then
  85.             repeat with i from 1 to number of items in fcontents
  86.                 if item i of fcontents contains "Now Playing:" then
  87.                     repeat with j from i + 1 to i + 40
  88.                         if item j of fcontents contains "/A" then
  89.                             set tmp to (item (j + 1) of fcontents) as string
  90.                             
  91.                             if last character of tmp is ")" then
  92.                                 repeat while last character of tmp is not "("
  93.                                     set tmp to (characters 1 thru ((length of tmp) - 1) of tmp) as string
  94.                                 end repeat
  95.                                 set tmp to (characters 1 thru ((length of tmp) - 2) of tmp) as string
  96.                             end if
  97.                             set title to ((item (j - 1) of fcontents) as string) & tmp & " - " & trackaddr
  98.                             exit repeat
  99.                         end if
  100.                     end repeat
  101.                     exit repeat
  102.                 end if
  103.             end repeat
  104.         end if
  105.         if title is null then
  106.             set title to trackname & " (Elapsed: " & trackpos & ") "
  107.         end if
  108.     else
  109.         set trackalbum to album of current track
  110.         set trackartist to artist of current track
  111.         set title to trackname & " - " & trackartist & " (" & trackalbum & ")"
  112.     end if
  113.     
  114.     set title to prefix & title
  115.     return title
  116. end tell
  117.  
  118. on gettitle()
  119.     set tmpfile to ((path to temporary items) as string) & "cursong.txt"
  120.     --set tmpfile to "MacOS:tmp:cursong.txt"
  121.     if exists tmpfile then
  122.         tell application "Finder" to delete file tmpfile
  123.     end if
  124.     tell application "URL Access Scripting"
  125.         download "http://nazgul:gryffon@www.somewhere.com:8000/admin?mode=sources" to file tmpfile replacing yes
  126.     end tell
  127.     set tfile to open for access file tmpfile
  128.     
  129.     set fcontents to read tfile using delimiter {"<", ">"}
  130.     close access tfile
  131.     tell application "Finder" to delete file tmpfile
  132.     set mytitle to null
  133.     repeat with i from 1 to number of items in fcontents
  134.         if item i of fcontents contains "localhost" then
  135.             set mytitle to (item (i + 4) of fcontents) as string
  136.             exit repeat
  137.         end if
  138.     end repeat
  139.     return mytitle
  140. end gettitle
  141.  
  142. on round_truncate(this_number, decimal_places)
  143.     if decimal_places is 0 then
  144.         set this_number to this_number + 0.5
  145.         return number_to_text(this_number div 1)
  146.     end if
  147.     
  148.     set the rounding_value to "5"
  149.     repeat decimal_places times
  150.         set the rounding_value to "0" & the rounding_value
  151.     end repeat
  152.     set the rounding_value to ("." & the rounding_value) as number
  153.     
  154.     set this_number to this_number + rounding_value
  155.     
  156.     set the mod_value to "1"
  157.     repeat decimal_places - 1 times
  158.         set the mod_value to "0" & the mod_value
  159.     end repeat
  160.     set the mod_value to ("." & the mod_value) as number
  161.     
  162.     set second_part to (this_number mod 1) div the mod_value
  163.     if the length of (the second_part as text) is less than the ¬
  164.         decimal_places then
  165.         repeat decimal_places - ¬
  166.             (the length of (the second_part as text)) times
  167.             set second_part to ("0" & second_part) as string
  168.         end repeat
  169.     end if
  170.     
  171.     set first_part to this_number div 1
  172.     set first_part to number_to_text(first_part)
  173.     set this_number to (first_part & "." & second_part)
  174.     
  175.     return this_number
  176. end round_truncate
  177.  
  178. on number_to_text(this_number)
  179.     set this_number to this_number as text
  180.     if this_number contains "E+" then
  181.         set x to the offset of "." in this_number
  182.         set y to the offset of "+" in this_number
  183.         set z to the offset of "E" in this_number
  184.         set the decimal_adjust to characters (y - (length of this_number)) thru ¬
  185.             -1 of this_number as string as number
  186.         if x is not 0 then
  187.             set the first_part to characters 1 thru (x - 1) of this_number as string
  188.         else
  189.             set the first_part to ""
  190.         end if
  191.         set the second_part to characters (x + 1) thru (z - 1) of this_number as string
  192.         set the converted_number to the first_part
  193.         repeat with i from 1 to the decimal_adjust
  194.             try
  195.                 set the converted_number to ¬
  196.                     the converted_number & character i of the second_part
  197.             on error
  198.                 set the converted_number to the converted_number & "0"
  199.             end try
  200.         end repeat
  201.         return the converted_number
  202.     else
  203.         return this_number
  204.     end if
  205. end number_to_text
  206.  
  207.